package cn.edu.sjtu.se.dslab.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import cn.edu.sjtu.se.dslab.component.method.MethodComponent;
import cn.edu.sjtu.se.dslab.dao.IBaseDao;
import cn.edu.sjtu.se.dslab.dao.IProjectMethodDao;
import cn.edu.sjtu.se.dslab.project.Project;
import cn.edu.sjtu.se.dslab.project.ProjectMethod;

@Repository("projectMethodDao")
public class ProjectMethodDaoImpl implements IProjectMethodDao {

	@Resource(name = "baseDao")
	private IBaseDao<ProjectMethod> baseDao;
	
	@Override
	public List<ProjectMethod> getListByProject(Project project) {
		StringBuffer hql = new StringBuffer();
		hql.append("from ProjectMethod pm where ");
		hql.append(" pm.project.id=");
		hql.append(project.getId());
		return baseDao.query(hql.toString());
	}

	@Override
	public List<ProjectMethod> getListByMethodComponent(MethodComponent methodComponent) {
		StringBuffer hql = new StringBuffer();
		hql.append("from ProjectMethod pm where ");
		hql.append(" pm.methodComponent.id=");
		hql.append(methodComponent.getId());
		return baseDao.query(hql.toString());
	}

	@Override
	public void save(ProjectMethod projectMethod) {
		baseDao.save(projectMethod);
	}

	@Override
	public boolean delete(ProjectMethod projectMethod) {
		baseDao.delete(projectMethod);
		return true;
	}

//	@Override
//	public PageBean<ProjectMethod> getPageBeanByProject(int pageNo, Project project)
//			throws DBException {
//		// TODO Auto-generated method stub
//		StringBuffer hql = new StringBuffer();
//		// 拼接sql语句
//		hql.append("from ProjectMethod up where ");
//		hql.append(" up.project.id=");
//		hql.append("" + project.getId());
//		PageBean<ProjectMethod> bean = baseDao.queryByspecialHqlForPage(pageNo,
//				Const.PAGESIZE, hql.toString());
//		return bean;
//	}

	@Override
	public boolean update(ProjectMethod projectMethod) {
		baseDao.update(projectMethod);
		return true;
	}

	@Override
	public boolean deleteById(long id) {
		baseDao.delById(ProjectMethod.class, id);
		return true;
	}

}
